from sqlalchemy import Column, Integer, String, Text, DateTime, Enum
from sqlalchemy.sql import func
from sqlalchemy.orm import relationship
from app.db.base_class import Base
from app.core.enums import QuestionType, Difficulty, QuestionStatus

class Question(Base):
    __tablename__ = "questions"

    id = Column(Integer, primary_key=True, index=True, autoincrement=True)
    title = Column(String(500), nullable=False)
    type = Column(String(32), nullable=False)
    options = Column(String(1000), nullable=True)
    answer = Column(Text, nullable=False)
    tags = Column(String(500), nullable=True)
    difficulty = Column(String(16), nullable=False)
    topic = Column(String(100), nullable=False)
    created_at = Column(DateTime, nullable=False, server_default=func.now())
    updated_at = Column(DateTime, nullable=False, server_default=func.now(), onupdate=func.now())
    reference_links = Column(String(500), nullable=True)
    explanation = Column(String(1000), nullable=True)
    status = Column(String(10), nullable=True, comment='draft  # 草稿 pending # 待审核  approved  # 已通过  rejected  # 已拒绝 archived  #已归档')

    # 建立与题集的多对多关系
    question_sets = relationship("QuestionSet", secondary="question_set_question", back_populates="questions") 